package com.gw.jpa.service.impl;

import com.gw.jpa.entity.Student;
import com.gw.jpa.repository.StudentRepository;
import com.gw.jpa.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class StudentServiceImpl implements StudentService {
    @Autowired //自动注入
    private StudentRepository studentRepository;
    @Override
    public Student addStudent(Student student) {
        return studentRepository.save(student);
    }

    @Override
    public Student getStudent(Integer sid) {
        return studentRepository.findById(sid).get();
    }

    @Override
    public List<Student> getStudentJquery() {
        return studentRepository.findAll();
    }

    @Override
    public Student updateStudent(Student student) {
        return studentRepository.save(student);
    }

    @Override
    public void deleteStudent(Integer sid) {
        studentRepository.deleteById(sid);
    }
}
